﻿Imports TNCDAL
Imports System.Data.Linq
Imports System.Linq


Public Class CVoyage
    Dim db As New TanNamChinhDataContext

    Public Sub New()

    End Sub

    Public Sub New(ByVal dataContext As TanNamChinhDataContext)
        db = dataContext
    End Sub

    Public Function SelectAllRecord() As IQueryable(Of tblVoyage)
        Dim voyage = From p In db.tblVoyages
                Select p
        Return voyage
    End Function

    Public Function SelectRecordById(ByVal id As Integer) As tblVoyage
        Dim voyage = (From p In db.tblVoyages
                 Where p.ID_Voyage = id
                 Select p).Single
        Return voyage
    End Function

    Public Sub Insert(ByVal obj As tblVoyage)
        db.tblVoyages.InsertOnSubmit(obj)
        db.SubmitChanges()
    End Sub

    Public Sub Update(ByVal obj As tblVoyage)
        Dim voyage = SelectRecordById(obj.ID_Voyage)
        voyage.ID_Line = obj.ID_Line
        voyage.ID_Vessel = obj.ID_Vessel
        voyage.ETA = obj.ETA
        voyage.ETD = obj.ETD
        voyage.ID_POD = obj.ID_POD
        voyage.ID_POL = obj.ID_POL
        voyage.VoyageNo = obj.VoyageNo
        db.SubmitChanges()
    End Sub

    Public Sub Delete(ByVal id As Integer)
        Dim ac = SelectRecordById(id)
        db.tblVoyages.DeleteOnSubmit(ac)
        db.SubmitChanges()
    End Sub
End Class
